#!/bin/sh
JAVA_OPTS=""
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote"
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote.port=9999"
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTS=$JAVA_OPTS" -Dcom.sun.management.jmxremote.ssl=false"
exec java $JAVA_OPTS -jar jajmx.jar -nocompdaemon -usejavacp -savecompiled "$0" "$@"
!#

import fr.janalyse.jmx._

val host  = args.headOption.getOrElse("localhost")
val port  = if (args.size>1) args.tail.head.toInt else 9999

JMX.once(host, port) { jmx =>
  for(mbean <- jmx.mbeans ;
      attr  <- mbean.attributes collect {case n:RichNumberAttribute => n};
      value <- mbean.getLong(attr)) {
    println("%s - %s = %d".format(mbean.name, attr.name, value))
  }
}
